﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TS.Bussiness;
using TS.Commons;
using TS.Entities;

namespace Tranco.Views
{
    public partial class CloseWebsiteManagement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                ConfigurationBussiness bu = new ConfigurationBussiness();
                var config = bu.GetConfig();

                drOpen.Items.FindByValue(config.IsClosed.ToStringOrDefault()).Selected =true;
                txtNotify.Text = config.ClosedComment;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            lblStatus.ForeColor = Color.Red;
            
            if (txtNotify.Text.Length <= 0)
            {
                lblStatus.Text = "Thông báo không được để trống";
                return;
            }
            Configuration config = new Configuration();
            try
            {
                config.IsClosed = drOpen.SelectedItem.Value.ToNumeric();
                config.ClosedComment = txtNotify.Text.ToStringOrDefault();

                var userB = new ConfigurationBussiness();
                int result = userB.UpdateClosed(config);
                if (result >= 0)
                {
                    lblStatus.Text = "Update thành công";
                    lblStatus.ForeColor = Color.Blue;
                }
                else
                {
                     lblStatus.Text = "Update không thành công";
                }
            }
            catch { }
        }
    }
}